package windbell.domain.risk.impl;

import edu.fudan.langlab.domain.document.IDocumentContainer;
import edu.fudan.langlab.domain.document.impl.DocumentStorageImpl;
import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import windbell.domain.risk.RiskReport;
import windbell.domain.risk.RiskReportQrCode;
import windbell.domain.risk.impl.RiskReportImpl;
import windbell.domain.risk.proxy.RiskReportQrCodeProxy;

@Entity
@DiscriminatorValue("RISKREPORTQRCODE_TYPE")
public class RiskReportQrCodeImpl extends DocumentStorageImpl implements RiskReportQrCode {
  public RiskReportQrCodeImpl() {
    super();
  }
  
  public RiskReportQrCodeImpl(final RiskReport riskReport) {
    super();
    this.riskReport = riskReport;
  }
  
  @JoinColumn(name = "riskReport_id")
  @ManyToOne(targetEntity = RiskReportImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RiskReport riskReport;
  
  public RiskReport getRiskReport() {
    return this.riskReport;
  }
  
  public IDocumentContainer getContainer() {
    return this.riskReport;
  }
  
  public static RiskReportQrCode create(final RiskReport riskReport, final IObjectFactory objectFactory) {
    windbell.domain.risk.RiskReportQrCode riskReportQrCode = new windbell.domain.risk.impl.RiskReportQrCodeImpl(
    	riskReport
    );
    objectFactory.create(riskReportQrCode);
    return riskReportQrCode;			
    
  }
  
  public static RiskReportQrCode createRiskReportQrCodeImpl(final RiskReport riskReport, final IObjectFactory objectFactory, final Procedure1<RiskReportQrCode> init) {
    windbell.domain.risk.RiskReportQrCode riskReportQrCode = new windbell.domain.risk.impl.RiskReportQrCodeImpl(
    	riskReport
    );
    objectFactory.create(riskReportQrCode);
    init.apply(riskReportQrCode);
    return riskReportQrCode;			
    
  }
  
  public RiskReportQrCodeProxy toProxy() {
    windbell.domain.risk.proxy.RiskReportQrCodeProxy proxy = new windbell.domain.risk.proxy.RiskReportQrCodeProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
